home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / C Internet Config / IC Application Source ƒ / C Source ƒ / IC CheckBox What.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-02  |  2.6 KB  |  119 lines  |  [TEXT/SPM ]

  1. /*
  2.     IC CheckBox What.c
  3.     
  4.     Custom code to handle a checkbox.
  5.     
  6.     IC CheckBoxes work as follows (since I am creating them, I can define
  7.     how they work ;-)
  8.     
  9.         True/False for a pref is determined by the existance
  10.             of the pref resource; if the resource exists, the
  11.             box is checked; if the resource doesn't exist, the
  12.             box is unchecked.
  13.         
  14.         This means that the resource associated with the
  15.         checkbox is very volatile and should not contain any
  16.         valuable information because it could be destroyed
  17.         (and lost) if someone unchecks and saves the changes.
  18.     
  19. */
  20.  
  21. #include "IC Types.h"
  22. #include "IC API.h"
  23.  
  24. #include "IC Window Globals.h"
  25. #include "IC Subs.h"
  26. #include "IC Dialogs.h"
  27. #include "IC Windows.h"
  28. #include "IC CheckBox What.h"
  29. #include "IC Document.h"
  30.  
  31. /*
  32.     WhatOpenCheckBox
  33.     
  34.     Called when a checkbox item is opened.  The control
  35.     is already created, we just need to set the initial
  36.     setting.
  37. */
  38. OSErr WhatOpenCheckBox(WindowType wt,short item){
  39.     OSErr err=noErr;
  40.     long attr;
  41.     short set=0;
  42.     Handle hand=NewHandle(0);
  43.     ICInstance inst=GetInstance();
  44.     StringPtr keyp=WindowInfo[wt].items[item]->key;
  45.     
  46.     err=ICMapErr(ICFindPrefHandle(inst,keyp,&attr,hand));
  47.     
  48.     if (err==noErr){
  49.         // then the pref exists; initial setting should be true
  50.         set=1;
  51.     }
  52.     
  53.     DisposeHandle(hand);
  54.     
  55.     // we know what the setting of the control should be,
  56.     // set it up now.
  57.     
  58.     SetDCtlValue(WindowInfo[wt].window,item,set);
  59.     
  60.     return noErr;
  61. }
  62.  
  63. /*
  64.     WhatClickCheckBox
  65.     
  66.     Called when a checkbox item has been clicked.  Toggle
  67.     the display in the window.
  68. */
  69. OSErr WhatClickCheckBox(WindowType wt,short item,EventRecord* er){
  70.     short val=GetDCtlValue(WindowInfo[wt].window,item);
  71.     
  72.     if (val!=0)
  73.         val=0;
  74.     else
  75.         val=1;
  76.     
  77.     SetDCtlValue(WindowInfo[wt].window,item,val);
  78.     
  79.     return noErr;
  80. }
  81.  
  82. /*
  83.     WhatFlushCheckBox
  84.     
  85.     Save the setting to the pref file.
  86. */
  87. OSErr WhatFlushCheckBox(WindowType wt,short item){
  88.     short val=GetDCtlValue(WindowInfo[wt].window,item);
  89.     Handle h;
  90.     OSErr err=noErr,junk;
  91.     ICInstance inst=GetInstance();
  92.     ICAttr attr;
  93.     Boolean wasSet=false;
  94.     StringPtr keyp=WindowInfo[wt].items[item]->key;
  95.     
  96.     h=NewHandle(0);
  97.     junk=ICMapErr(ICFindPrefHandle(inst,keyp,&attr,h));
  98.     if (junk==noErr)
  99.         wasSet=true;
  100.     DisposeHandle(h);
  101.     
  102.     if ((val==0)&&(wasSet)){
  103.         // need to delete the pref; it exists
  104.         ICDeletePref(GetInstance(),WindowInfo[wt].items[item]->key);
  105.         DirtyDocument();
  106.     } else if ((val==1)&&(!wasSet)){
  107.         // need to ensure pref exists
  108.         h=NewHandle(2); // create a new handle to two bytes
  109.         if (h!=(Handle)0){
  110.             ICSetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,
  111.                 (ICAttr)0,h);
  112.             DisposeHandle(h);
  113.             DirtyDocument();
  114.         } else
  115.             err=MemError();
  116.     }
  117.     return err;
  118. }
  119.